package com.xxcxcxcx.jobsystem.mixin.job.Brewmaster;

import com.xxcxcxcx.jobsystem.Main;
import com.xxcxcxcx.jobsystem.common.Job.Brewmaster.Brewmaster;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.effect.MobEffectInstance;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import javax.annotation.Nullable;
import java.util.List;
import java.util.stream.Collectors;

import static com.xxcxcxcx.jobsystem.common.Job.Brewmaster.Brewmaster.*;

@Mixin(net.minecraft.world.item.alchemy.PotionUtils.class)
public class PotionUtilMixin {

    @Inject(method = "getAllEffects(Lnet/minecraft/nbt/CompoundTag;)Ljava/util/List;", at = @At("RETURN"), cancellable = true)
    private static void originsClasses$modifyPotion(@Nullable CompoundTag nbt, CallbackInfoReturnable<List<MobEffectInstance>> cir) {
        if(nbt != null) {
            if(Brewmaster.hasPotionBonus(nbt)) {
                int level = nbt.getCompound(Main.MOD_ID).getInt(Refining+RefiningLevel);
                float time = nbt.getCompound(Main.MOD_ID).getFloat(Refining+Refiningtime);
                cir.setReturnValue(cir.getReturnValue().stream().map((a)->Brewmaster.applyPotionBonus(a,level,time)).collect(Collectors.toList()));
            }
        }
    }

}
